using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Madason.MetaModel.Validation;

namespace Madason.MetaModel.DAO.Tests
{
	[TestFixture]
	public class TestPersistedAttribute
	{
		[Test]
		public void TestAttributeType()
		{
			Model model = new Model();
			Class containingClass = new Class();
			PersistedAttribute attr = new PersistedAttributeCSharp();
			containingClass.Attributes.Add(attr);
			attr.Class = containingClass;
			model.Classes.Add(containingClass);
			containingClass.Namespace = model;
			Class someDT = new Class();
			model.Classes.Add(someDT);
			someDT.Id = Guid.NewGuid().ToString();
			someDT.Name = "UnknownDT";
			attr.TypeId = someDT.Id;

			ValidationIssueList validationIssues = new ValidationIssueList();
			attr.Validate(validationIssues);
			Assert.IsTrue(validationIssues.ContainsMessage(
				String.Format(PersistedAttribute.ERROR_UNSUPPORTED_TYPE, someDT.Name)), 
				"Entity doesn't complain about wron datatype");
		}

		[Test]
		public void TestAttributeTypeForPK()
		{
			Model model = new Model();
			Class containingClass = new Class();
			PrimaryKeyAttribute attr = new PrimaryKeyAttribute();
			containingClass.Attributes.Add(attr);
			attr.Class = containingClass;
			model.Classes.Add(containingClass);
			containingClass.Namespace = model;
			Class someDT = new Class();
			model.Classes.Add(someDT);
			someDT.Id = Guid.NewGuid().ToString();
			someDT.Name = "double";
			attr.TypeId = someDT.Id;

			ValidationIssueList validationIssues = new ValidationIssueList();
			attr.Validate(validationIssues);
			Assert.IsTrue(validationIssues.ContainsMessage(
				String.Format(PrimaryKeyAttribute.ERROR_UNSUPPORTED_TYPE, someDT.Name)),
				"PK doesn't complain about wrong datatype");
		}
	}
}
